package com.chenfan.mcn.controller;

import com.chenfan.mcn.config.UserVoContextHolder;
import com.chenfan.mcn.extension.Res;
import com.chenfan.mcn.model.vo.StarPlatInfoVO;
import com.chenfan.mcn.model.vo.StarPlatSelectVO;
import com.chenfan.mcn.service.StarPlatformInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 红人平台信息
 * @author tangwei
 * Date:     2021/1/22 9:51
 * Description: 红人平台信息
 */
@RestController
@RequestMapping("/platform")
public class StarPlatformInfoController {

    @Autowired
    private StarPlatformInfoService starPlatformInfoService;

    /**
     * 红人昵称模糊查询平台对应的红人
     * @param starName
     * @return
     */
    @GetMapping("/getByName")
    public Res<List<StarPlatInfoVO>> getByName(@RequestParam String starName) {
        return Res.ok(starPlatformInfoService.getByName(starName));
    }

    /**
     * 获取所有红人平台信息
     * @param starType 红人类型 （不填默认取内部、外部红人）
     * @param starStatus 红人状态
     * @param platformStatus 平台状态
     * @param platformId 平台ID
     * @return 返回值
     */
    @GetMapping("/getAll")
    public Res<List<StarPlatInfoVO>> getAll(@RequestParam(required = false) Integer starType,
                                            @RequestParam(required = false) Integer starStatus,
                                            @RequestParam(required = false) Integer platformStatus,
                                            @RequestParam(required = false) String platformId,
                                            @RequestParam(required = false) Long starId) {
        return Res.ok(starPlatformInfoService.getAll(starType,starStatus,platformStatus,platformId,starId));
    }
    /**
     * 红人平台启用禁用
     *
     * @param id         请求参数
     * @param platformStatus 请求参数
     * @return 返回值
     */
    @GetMapping(value = "/updatePlatformStatus", produces = {"application/json;charset=UTF-8"})
    public Res<Object> updatePlatformStatus(@RequestParam("id") Long id, @RequestParam("platformStatus") Integer platformStatus) {
        starPlatformInfoService.updatePlatformStatus(id, platformStatus);
        return Res.ok();
    }

    /**
     * 获取全部的红人平台昵称-下拉框接口
     * @return
     */
    @GetMapping("/getAllStarPlatSelect")
    public Res<List<StarPlatSelectVO>> getAllStarPlatSelect() {
        return Res.ok(starPlatformInfoService.getAllStarPlatSelect(UserVoContextHolder.getTenantId()));
    }
}